﻿#pragma once
#include "zyCtrol.h"

namespace DarkMoonUI {

#define zyButtonState_Hover 65536

#define PBS_NORMAL 1
#define PBS_HOT 2
#define PBS_PRESSED 3
#define PBS_DISABLED 4
#define PBS_DEFAULTED 5

#define	BP_PUSHBUTTON 1
#define	BP_CHECKBOX 3

	class zyButtonEx : public  zyCtrol
	{
	public:

	public:
		zyButtonEx();
		~zyButtonEx();
		static void  WINAPI zyButtonEx_Destroy(zyObject* obj);
		static LRESULT WINAPI zyButtonEx_WndProc(zyObject* obj, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL* bHandled);
		static LRESULT WINAPI zyButtonEx_ChildWndProc(zyObject* obj, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, BOOL* bHandle);

		BOOL 创建(HWND 参数_父窗口, const std::wstring& 参数_标题 = L"", POINT 参数_位置 = POINT{ 0, 0 }, POINT 参数_尺寸 = POINT{ 60, 120 },
			int 参数_ID = 0, int 参数_窗口风格 = 0, int 参数_扩展风格 = 0);
		BOOL 创建(zyWindow& 参数_父窗口, const std::wstring& 参数_标题 = L"", POINT 参数_位置 = POINT{ 0, 0 }, POINT 参数_尺寸 = POINT{ 60, 120 },
			int 参数_ID = 0, int 参数_窗口风格 = 0, int 参数_扩展风格 = 0);
		int 圆角度(int 参数_圆角度);
		bool 绑定(HWND 参数_父窗口, int 参数_资源ID, bool 参数_使用默认字体);
		bool 绑定窗口句柄(HWND 参数_窗口句柄);
		std::wstring 标题(const std::wstring& 参数_标题);
		int 背景色(int 参数_背景色 /*RGB*/);
		int 文本色(int 参数_背景色 /*RGB*/);
		bool 通常图片(Gdiplus::Image* 参数_图片);
		ARGB 通常颜色(ARGB 参数_透明色ARGB);
		bool 点燃图片(Gdiplus::Image* 参数_图片);
		ARGB 点燃颜色(ARGB 参数_透明色ARGB);
		bool 按下图片(Gdiplus::Image* 参数_图片);
		ARGB 按下颜色(ARGB 参数_透明色ARGB);
		bool 禁止图片(Gdiplus::Image* 参数_图片);
		ARGB 禁止颜色(ARGB 参数_透明色ARGB);
		bool 焦点图片(Gdiplus::Image* 参数_图片);
		ARGB 焦点颜色(ARGB 参数_透明色ARGB);
		bool 图标(Gdiplus::Image* 参数_图片);
		SIZE 图标尺寸(SIZE& 参数_尺寸);
		int 图标左偏移(int 参数_图标左偏移);
		int 图标上偏移(int 参数_图标上偏移);
		int 图标右偏移(int 参数_图标右偏移);
		int 图标下偏移(int 参数_图标下偏移);
		int 图标对齐方式(int 参数_图标对齐方式);
		int 文本对齐方式(int 参数_文本对齐方式);

		//调用了此方法后，图片按九宫方式绘制.参数_左边如果为0，则取消九宫绘制.后面参数则默认参数_左边
		void 置图片九宫(int 参数_左边 = 3, int 参数_顶边 = -1, int 参数_右边 = -1, int 参数_底边 = -1);
	protected:
		void OnNCDestroy();
		void zyButtonEx_OnMouseMove(HWND hWnd);
		void zyButtonEx_OnMouseLeave(HWND hWnd);
		RectF GetAlignRect(const RectF& srcRect, Align align, float width, float height, float marginLeft, float marginTop,
			float marginRight, float marginBottom
		);
		void SetTextAlignment(Gdiplus::StringFormat& stringFormat, LONG_PTR align);
		void CalculateLayout(const RectF& rcSrc, TextImageRelation relation, float imgWidth, float imgHeight, float textWidth,
			float textHeight, float minTextWidth, float minTextHeight, RectF& desImgRect, RectF& desTextRect);
		void zyButtonEx_DrawIconAndText(HWND hWnd, Gdiplus::Graphics* g, int state, RECT rcItem);
		void zyButtonEx_DrawImage(HWND hWnd, HDC hdc, Gdiplus::Graphics* g, HTHEME htheme, int state, RECT rcItem);
		void zyButtonEx_DrawBack(HWND hWnd, Gdiplus::Graphics* g, RECT rcItem);
		void zyButtonEx_DrawButton(HWND hWnd, HDC hdc, int state, RECT rc);
		void zyButtonEx_OnDrawItem(HWND hWnd, WPARAM wParam, DRAWITEMSTRUCT* dis);
	};

}

